package cn.edu.usts.sbmpservice.service.impl;


import cn.edu.usts.sbmpservice.dao.UserDao;
import cn.edu.usts.sbmpservice.dao.YljgjxcDao;
import cn.edu.usts.sbmpservice.pojo.User;
import cn.edu.usts.sbmpservice.pojo.Yljgjxc;
import cn.edu.usts.sbmpservice.service.UserService;
import cn.edu.usts.sbmpservice.utils.util;
import org.springframework.beans.factory.annotation.Autowired;

import javax.jws.WebService;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

//@Component
@WebService(serviceName = "UserService", // 与接口中指定的name一致
        targetNamespace = "http://service.sbmpservice.usts.edu.cn", // 与接口中的命名空间一致,一般是接口的包名倒
        endpointInterface = "cn.edu.usts.sbmpservice.service.UserService"// 接口地址
)
public class UserServiceImpl implements UserService {

        @Override
        public String sayHello(String userId, String userName) {
            System.out.println("sayHello");
            return "say hello || userId = "+ userId + "|| userName = "+ userName;
        }


        @Autowired
        private UserDao userDao;

        @Override
        public int addUser(User user ){

            System.out.println("addUser");

            return userDao.addUser(user);
        }
        @Override
        public User queryUser(Integer id){
            System.out.println("queryUser"+" "+id);
            User user = userDao.queryUser(id);
            System.out.println(user);
            return userDao.queryUser(id);
        }


        @Autowired
        private YljgjxcDao yljgjxcDao;
        @Override
        public void disposeData(String data) throws ParseException {

            String[] sdata = data.split("@");
            SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");

//            Date date = formatter.parse(s);
            for (String sdatum : sdata) {
                String[] split = sdatum.split("\\|");
//                System.out.println(split);
                Date kcrq= ft.parse(split[0]);
                int number = Integer.parseInt(split[4]);

                Yljgjxc yljgjxc = new Yljgjxc(kcrq,split[1],split[2],split[3],number);
//                System.out.println(yljgjxc.toString());
                yljgjxcDao.insert(yljgjxc);


            }

            Yljgjxc a = yljgjxcDao.query("01");
            System.out.println(a);

        }




}
